﻿@*
*@

@using System.Diagnostics;
@using System.Collections;
@using System.Reflection;
@using System.Runtime.Versioning;
@using Microsoft.AspNetCore.Http
@using NewLife.Common;
@using HttpContext = NewLife.Web.HttpContext
@inject IHttpContextAccessor HttpContextAccessor
@using NewLife;
@using NewLife.Reflection;


@{
    //Layout = NewLife.Cube.Setting.Current.Layout;

    ViewBag.Title = "服务器变量列表";
    var httpContext = HttpContextAccessor.HttpContext;
    var req = httpContext.Request;
    // ASP.NET Core中没有ServerVariables的对应实现，需要换一种方式，可以在HttpContext.Request.Headers中获取
}

<div class="layui-fluid" id="mainpage">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">
                    服务器变量列表
                </div>
                <div class="layui-card-body">
                    <div class="layui-form layui-border-box layui-table-view">
                        <div class="layui-table-box">
                            <div class="layui-table-header">
                                <table class="layui-table" cellspacing="0" cellpadding="0" border="0" lay-size="sm" style="width:100%">
                                    <thead>
                                        <tr>
                                            <th>
                                                <div class="layui-table-cell laytable-cell-1-0-0" data-id="1-0-0">
                                                    <span>
                                                        名称
                                                    </span>
                                                </div>
                                            </th>
                                            <th>
                                                <div class="layui-table-cell laytable-cell-1-0-1" data-id="1-0-1">
                                                    <span>
                                                        数值
                                                    </span>
                                                </div>
                                            </th>
                                        </tr>
                                    </thead>
                                </table>
                            </div>
                            <div class="layui-table-body layui-table-main">
                                <table class="layui-table" cellspacing="0" cellpadding="0" border="0" lay-size="sm" style="width:100%">
                                    <tbody>
                                        @foreach (var kv in req.Headers)
                                        {
                                            var v = kv.Value.ToString();
                                            v = v.Replace("\r\n", "</br>");
                                            var key = kv.Key;
                                            if (key.EqualIgnoreCase("HTTP_COOKIE")) { v = v.Replace(";", "</br>"); }
                                            <tr>
                                                <td>
                                                    <div class="layui-table-cell laytable-cell-1-0-0" data-id="1-0-0">
                                                        @key
                                                    </div>
                                                </td>
                                                <td>
                                                    <div class="layui-table-cell laytable-cell-1-0-1" data-id="1-0-1">
                                                        @Html.Raw(v)
                                                    </div>
                                                </td>
                                            </tr>
                                        }
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">
                    Request变量列表&nbsp;&nbsp;&nbsp;&nbsp;@req.GetType().FullName
                </div>
                <div class="layui-card-body">
                    <div class="layui-form layui-border-box layui-table-view">
                        <div class="layui-table-box">
                            <div class="layui-table-header">
                                <table class="layui-table" cellspacing="0" cellpadding="0" border="0" lay-size="sm" style="width:100%">
                                    <thead>
                                        <tr>
                                            <th>
                                                <div class="layui-table-cell laytable-cell-1-0-0" data-id="1-0-0">
                                                    <span>
                                                        名称
                                                    </span>
                                                </div>
                                            </th>
                                            <th>
                                                <div class="layui-table-cell laytable-cell-1-0-1" data-id="1-0-1">
                                                    <span>
                                                        数值
                                                    </span>
                                                </div>
                                            </th>
                                        </tr>
                                    </thead>
                                </table>
                            </div>
                            <div class="layui-table-body layui-table-main">
                                <table class="layui-table" cellspacing="0" cellpadding="0" border="0" lay-size="sm" style="width:100%">
                                    <tbody>
                                        @foreach (var pi in req.GetType().GetProperties())
                                        {
                                            var type = pi.PropertyType;
                                            if (pi.GetIndexParameters().Length > 0 || (type != typeof(String)
                                                                                       && type != typeof(Uri)
                                                                                       && type != typeof(PathString)
                                                                                       && type != typeof(HostString)
                                                                                       && !typeof(Boolean).IsAssignableFrom(type)
                                                                                       && !typeof(String).IsAssignableFrom(type)))
                                            {
                                                continue;
                                            }
                                            var v = req.GetValue(pi) + "";
                                            v = v.Replace("\r\n", "</br>");
                                            <tr>
                                                <td>
                                                    <div class="layui-table-cell laytable-cell-1-0-0" data-id="1-0-0">
                                                        @pi.Name
                                                    </div>
                                                </td>
                                                <td>
                                                    <div class="layui-table-cell laytable-cell-1-0-1" data-id="1-0-1">
                                                        @Html.Raw(v)
                                                    </div>
                                                </td>
                                            </tr>
                                        }
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

@section scripts{
    <script>
        layui.use(['jquery'], function () {
            var $ = layui.$;

            setTableScroll();

            setTable();
        });
    </script>
}